import cTitle from "components/title";
import { Toast, Dialog } from 'vant';
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
        store_id: '',
        language: "",
        store: "",
        store_id: "",
        commodity_data: [],
        goods_length: "",
        type: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        goods_audit: 0,
        goods_name: ""
    };
  },
  activated() {
    this.store_id=this.$route.params.store_id;
    this.getList()
  },
  methods: {
    initData(){
      
    },
    getList(){
        let json={store_id:this.store_id};
      $http
        .post(
          "HuanNiu.list_ps_muban",
          json,
          "获取中"
        )
        .then(
          response => {
            if (response.result == 1) {
                let arr = response.data
                this.commodity_data = arr.map((item,index)=> {
                    return {
                        ...item,
                        edit_active: 0
                    }
                })
            } else {
              Toast(response.msg);
            }
          });
    },
    routeTake(){
        this.$router.push(this.fun.getUrl("AddFreightTemplate", { store_id: this.store_id,type:0 }))
        
    },
    editJumpEvent(index,id){
        this.$router.push(this.fun.getUrl("AddFreightTemplate", { store_id: this.store_id,type:1,template_id:id }))
    },
    moreEvent(index) {
        var o = index;
        this.commodity_data.forEach((item,indexs)=>{
            if(o == indexs){
                item.edit_active =1
            }else {
                item.edit_active = 0
            }
             
        })
      
    },
    openDialog(index,id){
      Dialog.confirm({
        title: "提示",
        message: '此操作将永久删除该模板, 是否继续?'
      })
        .then(() => {
          console.log('确认')
          this.delTemplate(id)
        })
        .catch(() => {
          console.log('取消')
        });
    },
    // 删除模板
    delTemplate(id) {
      let json = {
          id: id
      };
      $http
          .post(
              "HuanNiu.del_ps_muban",
              json,
              " "
          )
          .then(
              response => {
                  if (response.result == 1) {
                      Toast('模板删除成功');
                      this.getList()
                  } else {
                      Toast(response.msg);
                  }
              });
  },
    
    
  },
  components: {
    cTitle
  }
};
